from .champion import Warrior
from typing import Dict, Any, Optional


class DaQiao(Warrior):
    """大乔 - 死亡召唤孙策"""
    
    def __init__(self):
        super().__init__(
            card_id="da_qiao",
            name="Da Qiao",
            image_path="Da Qiao.jpg",
            description="\nDeath: Summon Sun Ce",
            cost=2,
            attack=1,
            hp=2
        )
    
    def on_death(self, game_state, player_id: str):
        """死亡时召唤孙策"""
        # 寻找空位召唤孙策
        battlefield = game_state.battlefields[player_id]
        for i, slot in enumerate(battlefield):
            if slot is None:
                # 创建孙策实例
                from .guard import SunCe
                sun_ce = SunCe()
                import uuid
                sun_ce.instance_id = f"{player_id}_{i}_sun_ce_{uuid.uuid4().hex[:8]}"
                sun_ce.position = i
                # 设置守护目标为召唤师
                sun_ce.guarding_target_id = f"{player_id}_summoner"
                battlefield[i] = sun_ce
                break


class HanXin(Warrior):
    """韩信 - 入场时己方所有随从+1/+1"""
    
    def __init__(self):
        super().__init__(
            card_id="han_xin",
            name="Han Xin",
            image_path="Han Xin.jpg",
            description="\nOn summon: All friendly minions get +1/+1",
            cost=6,
            attack=4,
            hp=6
        )
    
    def on_summon(self, game_state, player_id: str):
        """入场时己方所有随从+1/+1"""
        battlefield = game_state.battlefields[player_id]
        for champion in battlefield:
            if champion and champion.is_alive():
                champion.attack += 1
                champion.hp += 1


class XiShi(Warrior):
    """西施 - 入场时选择一名敌方英雄造成1点伤害"""
    
    def __init__(self):
        super().__init__(
            card_id="xi_shi",
            name="Xi Shi",
            image_path="Xi Shi.jpg",
            description="\nOn summon: Deal 1 damage to target enemy champion",
            cost=2,
            attack=2,
            hp=2
        )
    
    def on_summon(self, game_state, player_id: str, effect_target: str = None):
        """入场时对目标造成1点伤害"""
        if not effect_target:
            return
        
        # 查找目标
        target = None
        if effect_target.endswith("_summoner"):
            # 攻击敌方召唤师
            enemy_id = effect_target.split("_summoner")[0]
            target = game_state.get_summoner(enemy_id)
        else:
            # 攻击敌方英雄
            target = game_state.get_champion_by_instance_id(effect_target)
        
        if target and target.is_alive():
            target_dead = target.take_damage(1)
            # 如果目标死亡，从战场移除
            if target_dead:
                game_state._remove_dead_champion(effect_target)


class YangYuhuan(Warrior):
    """杨玉环 - 召唤：使所有友方单位获得+1攻击"""
    
    def __init__(self):
        super().__init__(
            card_id="yang_yuhuan",
            name="Yang Yuhuan",
            image_path="Yang Yuhuan.jpg",
            description="\nOn summon: All friendly units gain +1 attack",
            cost=1,
            attack=1,
            hp=1
        )
    
    def on_summon(self, game_state, player_id: str):
        """召唤时使所有友方单位获得+1攻击"""
        battlefield = game_state.battlefields[player_id]
        for champion in battlefield:
            if champion and champion.is_alive():
                champion.attack += 1


class BaiQi(Warrior):
    """白起 - 召唤时友方pp上限减1"""
    
    def __init__(self):
        super().__init__(
            card_id="bai_qi",
            name="Bai Qi",
            image_path="Bai Qi.jpg",
            description="\nOn summon: Friendly PP cap -1",
            cost=3,
            attack=6,
            hp=6
        )
    
    def on_summon(self, game_state, player_id: str):
        """召唤时友方pp上限减1"""
        if game_state.max_pp[player_id] > 0:
            game_state.max_pp[player_id] -= 1


class WuZetian(Warrior):
    """武则天 - 高攻高血战士"""
    
    def __init__(self):
        super().__init__(
            card_id="wu_zetian",
            name="Wu Zetian",
            image_path="Wu Zetian.jpg",
            description="",
            cost=7,
            attack=10,
            hp=10
        )
